local path V:\docs\sc_ops\budziak_lempert_jlc_replication
*replace path above with location where aesthetic_data_compact.dta is saved.
use "`path'\aesthetic_data_compact.dta", clear



************************main regressions****************************************

local motvars c.CLR_es c.__z_amici __lsalience __sigquestion __gconflict c.__compmq  
local lcapvars  __missues  c.__majwl c.DS_total_docket c.__tteot c.__meritsdocket ///
 c.__mqsd c.majvotes  


********Table A1***********
regress __fkgl   `motvars'  `lcapvars'   i.issuearea ib5.__ajfe if __acc==0 , 	baselev robust
est store mLc



foreach v in `motvars' `lcapvars'{
	qui summ `v' if e(sample), det
	local x=subinstr("`v'","c.","",.)
	local `x'_p10=r(p10)
	local `x'_p90=r(p90)
	local `x'_min=r(min)
	local `x'_max=r(max)
}


margins, at(CLR_es=`CLR_es_p10' __z_amici=`__z_amici_p10'  __lsalience=0 ///
__sigquestion=0  __gconflict=1 __compmq=`__compmq_p10'  __missues=1 __majwl=`__majwl_p90' ///
 DS_total_docket=`DS_total_docket_p90' __meritsdocket=`__meritsdocket_p90' ///
__tteot=`__tteot_p10' __mqsd=`__mqsd_p90'  majvotes=`majvotes_p10' ) ///
at(CLR_es=`CLR_es_p90' __z_amici=`__z_amici_p90'  __lsalience=1 ///
__sigquestion=1  __gconflict=0 __compmq=`__compmq_p90' __missues=0 __majwl=`__majwl_p10' /// 
 DS_total_docket=`DS_total_docket_p10' __meritsdocket=`__meritsdocket_p10' ///
__tteot=`__tteot_p90' __mqsd=`__mqsd_p10'  majvotes=`majvotes_p90') post
***Table 1 output above**** 


mlincom (2-1) //lo-cost - hi-cost ****(Table 2, Row 1)



**for the entire ct--no potentially endogenous vars:
**though note the argument for mqsd at least as endogenous is fairly preposterous

local motvars c.CLR_es c.__z_amici __lsalience __sigquestion __gconflict c.__compmq  
local llcapvars  __missues  c.__majwl c.DS_total_docket c.__tteot c.__meritsdocket // c.__mqsd c.majvotes  

regress __fkgl   `motvars'  `llcapvars'   i.issuearea ib5.__ajfe if __acc==0 , 	baselev robust
est store mLLc


foreach v in `motvars' `llcapvars'{
	qui summ `v' if e(sample), det
	local x=subinstr("`v'","c.","",.)
	local `x'_p10=r(p10)
	local `x'_p90=r(p90)
	local `x'_min=r(min)
	local `x'_max=r(max)
}



margins, at(CLR_es=`CLR_es_p10' __z_amici=`__z_amici_p10'  __lsalience=0 ///
__sigquestion=0  __gconflict=1 __compmq=`__compmq_p10'  __missues=1 __majwl=`__majwl_p90' ///
 DS_total_docket=`DS_total_docket_p90' __meritsdocket=`__meritsdocket_p90' ///
__tteot=`__tteot_p10'  ) ///
at(CLR_es=`CLR_es_p90' __z_amici=`__z_amici_p90'  __lsalience=1 ///
__sigquestion=1  __gconflict=0 __compmq=`__compmq_p90' __missues=0 __majwl=`__majwl_p10' /// 
 DS_total_docket=`DS_total_docket_p10' __meritsdocket=`__meritsdocket_p10' ///
__tteot=`__tteot_p90' ) post



mlincom (2-1) //lo cost - hi cost ****(Table 2, Row 2).



estout mLc mLLc , cells(b(star fmt(3)) se(par fmt(2))) mlabels(FULL LIMITED) ///
legend stats(N bic)  label starlevels(* .05) // starlevels(+ .1 * .05 ** .01 *** .001)



************fig 1:********************

est restore mLc
histogram __fkgl if __fkgl>10 & __fkgl<20 & e(sample)==1, bin(36) ///
frequency title(Distribution of Flesch-Kincaid Grade Level) ///
subtitle("Majority Opinions 1955-2008")





****create pairwise comparison of justice FE coeffs:****




local vars ak as bw ct ds ew ff hab hlb jh js lp oj ps rg sb so tc tm web wjb wd wr 
*local vars ak as bw ew hab hlb jh js lp oj ps so tc tm web wjb wd wr 
local i=1
gen jinit=""
foreach v of local vars{
gen `v' =.
format `v' %6.1f
replace jinit="`v'" in `i'
local i=`i'+1
 }

list jinit-wr in 1/23


local motvars c.CLR_es c.__z_amici __lsalience __sigquestion __gconflict c.__compmq  
local lcapvars  __missues  c.__majwl c.DS_total_docket c.__tteot c.__meritsdocket ///
 c.__mqsd c.majvotes  
  
 
local vars ak as bw ct ds ew ff hab hlb jh js lp oj ps rg sb so tc tm web wjb wd wr
*local vars ak as bw ew hab hlb jh js lp oj ps so tc tm web wjb wd wr
tokenize `vars'
 


**baseline model:
qui forvalues n=1/23{
	regress __fkgl ib`n'.__ajfe `motvars' `lcapvars'     ///
	i.issuearea  if __acc==0, baselev
	est store m2j`n'b

	estout m2j`n'b, cells(b(star fmt(3)) se(par fmt(2)))  ///
	legend stats(N bic) starlevels(+ .1 * .05 ** .01 *** .001) label ///


	mat A=r(coefs)
	mat li A

	forvalues m=1/23{
		if A[`m',3] < .05{
			replace ``m''=A[`m',1] in `n'  //``m'' works b/c we have tokenized `vars' above 
		}	
	}
}
****SIG differences**********(Table 3)
list jinit-lp ps-wr if _n!=13 & _n<24, noobs clean
egen __sigdiffs=rownonmiss(ak-lp ps-wr) if _n!=13 & _n<24
summ __sigdiffs, det
ret li 
// number of sig diffs are r(sum)/2=168.  total pairwise comparisons is (22*22-22)/2=231
drop __sigdiffs
qui foreach x of varlist ak-wr{
	replace `x'=.
}



qui forvalues n=1/23{
	estout m2j`n'b, cells(b(star fmt(3)) se(par fmt(2)))  ///
	legend stats(N bic) starlevels(+ .1 * .05 ** .01 *** .001) label ///


	mat A=r(coefs)
	mat li A

	forvalues m=1/23{
		if A[`m',3] > .05 & `m' !=`n'{
			replace ``m''=A[`m',1] in `n'  //``m'' works b/c we have tokenized `vars' above 
		}
	}
}
****NS differences**********
list jinit-lp ps-wr if _n!=13 & _n<24, noobs 
summ ak-lp ps-wr if _n!=13 & _n<24
qui foreach x of varlist ak-wr{
	replace `x'=.
}





*************mean of difference magnitudes**************

local motvars c.CLR_es c.__z_amici __lsalience __sigquestion __gconflict c.__compmq  
local lcapvars  __missues  c.__majwl c.DS_total_docket c.__tteot c.__meritsdocket ///
 c.__mqsd c.majvotes  
  
 
local vars ak as bw ct ds ew ff hab hlb jh js lp oj ps rg sb so tc tm web wjb wd wr
*local vars ak as bw ew hab hlb jh js lp oj ps so tc tm web wjb wd wr
tokenize `vars'
 


**baseline model:
qui forvalues n=1/23{
	regress __fkgl ib`n'.__ajfe `motvars' `lcapvars'     ///
	i.issuearea  if __acc==0, baselev
	est store m2j`n'b

	estout m2j`n'b, cells(b(star fmt(3)) se(par fmt(2)))  ///
	legend stats(N bic) starlevels(+ .1 * .05 ** .01 *** .001) label ///


	mat A=r(coefs)
	mat li A

	forvalues m=1/23{
		if A[`m',3] < 1{ //trivial condition so don't have to rewrite code.
			replace ``m''=A[`m',1] in `n'  //``m'' works b/c we have tokenized `vars' above 
		}	
	}
}

*list jinit-lp ps-wr if _n!=13 & _n<24, noobs 

foreach var of varlist ak-lp ps-wr{
	replace `var'=abs(`var')
}

egen __mad=rowmean(ak-lp ps-wr)
list jinit __mad if _n !=13 & _n<24, noobs //avg magnitude of difference between own and other justices' predicted FKGL
list jinit-lp ps-wr __mad if _n !=13 & _n<24


drop __mad


qui foreach x of varlist ak-wr{
	replace `x'=.
}










****hi-cost vs lo-cost by justice****

local motvars c.CLR_es c.__z_amici __lsalience __sigquestion __gconflict c.__compmq  
local lcapvars  __missues  c.__majwl c.DS_total_docket c.__tteot c.__meritsdocket ///
 c.__mqsd c.majvotes  

 forvalues i=1/23{
cap gen __j`i'dummy=0 if __ajfe !=`i' & __ajfe !=.
replace __j`i'dummy=1 if __ajfe==`i'
}


gen __rjname=""
gen __hicost=.
gen __locost=.
gen __diff=.
gen __pdiff=.
gen __rjopct=.





forvalues i=1/23{
	regress __fkgl   `motvars'  `lcapvars'   i.issuearea if __acc==0 & __ajfe==`i' , 	baselev robust




	foreach v in `motvars' `lcapvars'{
		qui summ `v' if e(sample), det
		local x=subinstr("`v'","c.","",.)
		local `x'_p10=r(p10)
		local `x'_p90=r(p90)
		local `x'_min=r(min)
		local `x'_max=r(max)
	}



	tab __ajfe if e(sample)
	replace __rjopct=r(N) in `i'
	
	margins, at(CLR_es=`CLR_es_p10' __z_amici=`__z_amici_p10'  __lsalience=0 ///
	__sigquestion=0  __gconflict=1 __compmq=`__compmq_p10'  __missues=1 __majwl=`__majwl_p90' ///
	DS_total_docket=`DS_total_docket_p90' __meritsdocket=`__meritsdocket_p90' ///
	__tteot=`__tteot_p10' __mqsd=`__mqsd_p90'  majvotes=`majvotes_p10' ) ///
	at(CLR_es=`CLR_es_p90' __z_amici=`__z_amici_p90'  __lsalience=1 ///
	__sigquestion=1  __gconflict=0 __compmq=`__compmq_p90' __missues=0 __majwl=`__majwl_p10' /// 
	DS_total_docket=`DS_total_docket_p10' __meritsdocket=`__meritsdocket_p10' ///
	__tteot=`__tteot_p90' __mqsd=`__mqsd_p10'  majvotes=`majvotes_p90') post

	
	
	ereturn list
	mat B=e(b)
	replace __hicost=B[1,1] in `i'
	replace __locost=B[1,2] in `i' 
	mlincom (2-1)
	replace __diff=r(est) in `i'
	replace __pdiff=r(p) in `i'
	replace __rjname="`:label (__ajfe) `i''" in `i'
}

list __rjname - __pdiff __rjopct in 1/23




**% of cases where ct is constrained

local motvars c.CLR_es c.__z_amici __lsalience __sigquestion __gconflict c.__compmq  
local lcapvars  __missues  c.__majwl c.DS_total_docket c.__tteot c.__meritsdocket ///
 c.__mqsd c.majvotes  


regress __fkgl   `motvars'  `lcapvars'   i.issuearea if __acc !=. , 	baselev robust 
//remove __acc condition; also J FEs since those were constructed condl on acc



*--------------------------------misc robustness checks:---------------------



***check for time trend***:
gen __decade=floor((term-1900)/10) //i.e., 5=1950s etc but obnoxiously 10=2000s.

local motvars c.CLR_es c.__z_amici __lsalience __sigquestion __gconflict c.__compmq  
local lcapvars  __missues  c.__majwl c.DS_total_docket c.__tteot c.__meritsdocket ///
 c.__mqsd c.majvotes 

regress __fkgl   `motvars'  `lcapvars'   i.issuearea ib5.__ajfe c.term if __acc==0 , baselev robust
regress __fkgl   `motvars'  `lcapvars'   i.issuearea ib5.__ajfe i.__decade if __acc==0 , baselev robust
*no obvious time trend; J FE magnitudes basically same.

*check basic result:
foreach v in `motvars' `lcapvars'{
	qui summ `v' if e(sample), det
	local x=subinstr("`v'","c.","",.)
	local `x'_p10=r(p10)
	local `x'_p90=r(p90)
	local `x'_min=r(min)
	local `x'_max=r(max)
}



margins, at(CLR_es=`CLR_es_p10' __z_amici=`__z_amici_p10'  __lsalience=0 ///
__sigquestion=0  __gconflict=1 __compmq=`__compmq_p10'  __missues=1 __majwl=`__majwl_p90' ///
 DS_total_docket=`DS_total_docket_p90' __meritsdocket=`__meritsdocket_p90' ///
__tteot=`__tteot_p10'  ) ///
at(CLR_es=`CLR_es_p90' __z_amici=`__z_amici_p90'  __lsalience=1 ///
__sigquestion=1  __gconflict=0 __compmq=`__compmq_p90' __missues=0 __majwl=`__majwl_p10' /// 
 DS_total_docket=`DS_total_docket_p10' __meritsdocket=`__meritsdocket_p10' ///
__tteot=`__tteot_p90' ) post



mlincom (2-1) //lo cost - hi cost



***conservatism***:
local motvars c.CLR_es c.__z_amici __lsalience __sigquestion __gconflict c.__compmq  
local lcapvars  __missues  c.__majwl c.DS_total_docket c.__tteot c.__meritsdocket ///
 c.__mqsd c.majvotes  

regress __fkgl   `motvars'  `lcapvars'   i.issuearea ib5.__ajfe post_mn if __acc==0  , baselev robust
*note J FE differences appear even larger.



*check basic result:
foreach v in `motvars' `lcapvars'{
	qui summ `v' if e(sample), det
	local x=subinstr("`v'","c.","",.)
	local `x'_p10=r(p10)
	local `x'_p90=r(p90)
	local `x'_min=r(min)
	local `x'_max=r(max)
}



margins, at(CLR_es=`CLR_es_p10' __z_amici=`__z_amici_p10'  __lsalience=0 ///
__sigquestion=0  __gconflict=1 __compmq=`__compmq_p10'  __missues=1 __majwl=`__majwl_p90' ///
 DS_total_docket=`DS_total_docket_p90' __meritsdocket=`__meritsdocket_p90' ///
__tteot=`__tteot_p10'  ) ///
at(CLR_es=`CLR_es_p90' __z_amici=`__z_amici_p90'  __lsalience=1 ///
__sigquestion=1  __gconflict=0 __compmq=`__compmq_p90' __missues=0 __majwl=`__majwl_p10' /// 
 DS_total_docket=`DS_total_docket_p10' __meritsdocket=`__meritsdocket_p10' ///
__tteot=`__tteot_p90' ) post



mlincom (2-1) //lo cost - hi cost


***conservatism w/o FEs--more appropriate in some ways:***
local motvars c.CLR_es c.__z_amici __lsalience __sigquestion __gconflict c.__compmq  
local lcapvars  __missues  c.__majwl c.DS_total_docket c.__tteot c.__meritsdocket ///
 c.__mqsd c.majvotes  

regress __fkgl   `motvars'  `lcapvars'   i.issuearea  post_mn if __acc==0  , baselev robust
*note J FE differences appear even larger.



*check basic result:
foreach v in `motvars' `lcapvars'{
	qui summ `v' if e(sample), det
	local x=subinstr("`v'","c.","",.)
	local `x'_p10=r(p10)
	local `x'_p90=r(p90)
	local `x'_min=r(min)
	local `x'_max=r(max)
}



margins, at(CLR_es=`CLR_es_p10' __z_amici=`__z_amici_p10'  __lsalience=0 ///
__sigquestion=0  __gconflict=1 __compmq=`__compmq_p10'  __missues=1 __majwl=`__majwl_p90' ///
 DS_total_docket=`DS_total_docket_p90' __meritsdocket=`__meritsdocket_p90' ///
__tteot=`__tteot_p10'  ) ///
at(CLR_es=`CLR_es_p90' __z_amici=`__z_amici_p90'  __lsalience=1 ///
__sigquestion=1  __gconflict=0 __compmq=`__compmq_p90' __missues=0 __majwl=`__majwl_p10' /// 
 DS_total_docket=`DS_total_docket_p10' __meritsdocket=`__meritsdocket_p10' ///
__tteot=`__tteot_p90' ) post



mlincom (2-1) //lo cost - hi cost





***"panel effects"--create dummy if j is in majority in a given case:

*(going to have to go old school b/c 5+ dummies==1 per case):
est restore mLc

cap drop __mmOJ-__mmWHITT
gen __mmOJ=0 if e(sample)==1 
levelsof __jln if e(sample)==1, local(jjj) //if majority==1 & (opinion==2 | opinion==3)
foreach jn of local jjj{
	gen tvmm`jn'=0
	replace tvmm`jn'=1 if majority==2  & __jln=="`jn'"
	egen __mm`jn'=max(tvmm`jn'),by(caseid)
	*replace 0 if was author:
	replace __mm`jn'=0 if __jln=="`jn'" //note that this makes sense b/c __jln is author in e(sample)
	la var __mm`jn' "1: `jn' was in majority but not author; 0: else."
	drop tvmm`jn'
	qui summ __mm`jn' if e(sample)==1, det
	if `r(sum)'<30{
	    di "__mm`jn'"
		replace  __mmOJ=1 if majority==2 & __mm`jn'==1 
		drop __mm`jn'
	}
}

*to see this works:
*edit caseid __jln __aumaj majority __mmOJ-__mmWHITT



local motvars c.CLR_es c.__z_amici __lsalience __sigquestion __gconflict c.__compmq  
local lcapvars  __missues  c.__majwl c.DS_total_docket c.__tteot c.__meritsdocket ///
 c.__mqsd c.majvotes  


regress __fkgl   `motvars'  `lcapvars'   i.issuearea ib5.__ajfe __mmOJ-__mmSCALIA  ///
__mmSTEVENS-__mmWHITT if __acc==0 , 	baselev robust //Souter omitted cat.
//no (sensible) panel effects--> no justices have panel fx sig more neg than Souter

*for sake of completeness, omit Douglas
regress __fkgl   `motvars'  `lcapvars'   i.issuearea ib5.__ajfe __mmOJ-__mmCLARK  ///
__mmFORTAS-__mmWHITT if __acc==0 , 	baselev robust //Douglas omitted cat.
//some hint of it here--> nine js have positive coeffs relative to WOD, max magnitude < .6


*fine, Scalia too:

regress __fkgl   `motvars'  `lcapvars'   i.issuearea ib5.__ajfe __mmOJ-__mmROBERTS  ///
__mmSOUTER-__mmWHITT if __acc==0 , 	baselev robust //Souter omitted cat.
//Scalia: 2 negative, would be expected due to chance.

*and then 2nd clearest to be symmetrical:
regress __fkgl   `motvars'  `lcapvars'   i.issuearea ib5.__ajfe __mmOJ-__mmBLACK  ///
__mmBRENNAN-__mmWHITT if __acc==0 , 	baselev robust //Blackmun omitted cat.
//nothing.


*check basic result:
foreach v in `motvars' `lcapvars'{
	qui summ `v' if e(sample), det
	local x=subinstr("`v'","c.","",.)
	local `x'_p10=r(p10)
	local `x'_p90=r(p90)
	local `x'_min=r(min)
	local `x'_max=r(max)
}



margins, at(CLR_es=`CLR_es_p10' __z_amici=`__z_amici_p10'  __lsalience=0 ///
__sigquestion=0  __gconflict=1 __compmq=`__compmq_p10'  __missues=1 __majwl=`__majwl_p90' ///
 DS_total_docket=`DS_total_docket_p90' __meritsdocket=`__meritsdocket_p90' ///
__tteot=`__tteot_p10'  ) ///
at(CLR_es=`CLR_es_p90' __z_amici=`__z_amici_p90'  __lsalience=1 ///
__sigquestion=1  __gconflict=0 __compmq=`__compmq_p90' __missues=0 __majwl=`__majwl_p10' /// 
 DS_total_docket=`DS_total_docket_p10' __meritsdocket=`__meritsdocket_p10' ///
__tteot=`__tteot_p90' ) post


mlincom (2-1) //lo cost - hi cost















